<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src='https://unpkg.com/@antv/l7'></script>
    <script src="https://lib.baomitu.com/jquery/2.2.4/jquery.js"></script>
    <style>
        * {
            margin: 0;
            padding: 0
        }

        #map {
            width: 100vw;
            height: 100vh;
        }

        html,
        body {
            overflow: hidden;
        }
    </style>
</head>

<body>
    <div id="map">

    </div>
    <script>
        var { Scene, GaodeMap } = L7;
        const scene = new Scene({
            id: 'map',
            map: new GaodeMap({
                /* dark|light|normal */
                style: 'normal', // 样式URL
                center: [120.19382669582967, 30.258134],
                pitch: 30,
                zoom: 3,
                // token: '3851594382e218c49865a4d6a5170b52',
            }),
            logoVisible: false
        });
        /*
        1、侧重地理数据的展示
        2、map是作为场景Scene的一个属性
        Scene场景  使用地图来实现地理数据的可视化
         */
        /* L7
        阿里
        高德 --阿里  国内
        国际 mapbox
         */
        var china_url = 'https://geo.datav.aliyun.com/areas_v3/bound/100000_full.json'
        /*
        PointLayer   image     circle
        LineLayer  stroke  line
        PolygonLayer  fill     fill
         */
        $.ajax({
            url: china_url
        }).then(data => {
            /* 设置高亮图层 */
            var high_layer = new L7.PolygonLayer({
                zIndex: 4
            })
            high_layer.source({
                type: "FeatureCollection",
                features: []
            }).color("#333")
            scene.addLayer(high_layer)
            var china_layer = new L7.PolygonLayer();
            china_layer.source(data)
                .color("#ff2d51")
                .style({
                    opacity: 0.3
                })
            scene.addLayer(china_layer)

            var line_layer = new L7.LineLayer();
            line_layer.source(data)
                .color("#333")
            // scene.addLayer(line_layer)
            // scene.addLayer(high_layer)
            /* 1、设置高亮图层 */
            /* 2、将点击的要素设置到高亮图层中 */
            china_layer.on("click", evt => {
                console.log(evt)
                var lngLat = evt.lngLat;
                var name = evt.feature.properties.name;
                high_layer.setData({
                    type: "FeatureCollection",
                    features: [evt.feature]
                })

                /* Popup弹窗显示 */
                const popup = new L7.Popup({
                    lngLat,
                    html: `<span>${name}</span>`,
                    closeButton: false
                })
                scene.addPopup(popup)
            })

            /* zIndex可以设置图层的堆叠顺序 */
        })
    </script>
</body>

</html>